package com.futvan.z.framework.util;

import com.futvan.z.erp.customer.crm_customer;
import com.futvan.z.erp.customer_notice.crm_customer_notice;
import com.futvan.z.framework.common.bean.Result;
import com.futvan.z.framework.core.z;
import com.futvan.z.system.zcode.z_code_detail;

/**
 * 云购工具类
 */
public class ShopUtil {


    /**
     * 给客户发通信信息
     * @param c
     * @param notice_type
     * @param title
     * @param info
     * @return
     */
    public static Result SendCustomerNotice(crm_customer c,String notice_type,String title,String info,String is_tips){
        Result result = new Result();
        if(z.isNotNull(c)){
            if(z.isNotNull(notice_type)){
                z_code_detail cd = z.code_detail.get("notice_type_"+notice_type);
                if(z.isNotNull(notice_type)){
                    if(z.isNotNull(title)){
                        if(z.isNotNull(info)){
                            //构建通知体
                            crm_customer_notice cn = new crm_customer_notice();
                            cn.setZid(z.newZid("crm_customer_notice"));
                            cn.setCreate_time(DateUtil.getDateTime());//发送时间
                            cn.setCustomid(c.getZid());//客户ID
                            cn.setIs_read("0");//是否阅读
                            //是否提示
                            if("1".equals(is_tips)){
                                cn.setIs_tips("1");//弹出提示
                            }else{
                                cn.setIs_tips("0");//不弹出提示
                            }
                            cn.setNotice_type(notice_type);//通知类型
                            cn.setTitle(title);//标题
                            cn.setInfo(info);//通知内容
                            //执行发送
                            int i = z.getSqlSession().insert("crm_customer_notice_insert",cn);
                            if(i==1){
                                result.setSuccess(cn);
                            }else{
                                result.setError("发送客户通知失败|intert 返回 i="+i);
                            }
                        }else{
                            result.setError("info is null");
                        }
                    }else{
                        result.setError("title is null");
                    }
                }else{
                    result.setError("notice_type未找到关联字典值");
                }
            }else{
                result.setError("notice_type is null");
            }
        }else{
            result.setError("crm_customer is null");
        }
        return result;
    }
}
